/**
 * Created by yindu on 2018/12/17.
 */
var express = require('express');
var router = express.Router();
var db = require('../libs/mysql');
//统一返回格式
var res_Data;
router.use( function(req, res, next) {
    res_Data = {
        code: 0,
        message: ''
    }
    next();
});

router.post('/',function (req,res) {
    var data = req.body.addContent;
    var username = data.username,
        phone = data.phone,
        add_time = data.add_time,
        message = data.message,
        home_id = data.home_id;
    if(username==''){
        res_Data.code = 1;
        res_Data.message = '姓名不能为空';
        res.json(res_Data);
        return;
    }
    if(phone==''){
        res_Data.code = 2;
        res_Data.message = '联系电话不能为空';
        res.json(res_Data);
        return;
    }
    if(add_time==''){
        res_Data.code = 3;
        res_Data.message = '报名时间不能为空';
        res.json(res_Data);
        return;
    }
    db.query(`INSERT INTO home_details ( username,phone,add_time,message,home_id) VALUES ('${username}','${phone}','${add_time}','${message}','${home_id}');`,(err)=>{
        if(err){
            res.send('增加报名人').end();
        }else {
            res_Data.message = '添加成功';
            res.json(res_Data);
            return;
        }
    })
})
module.exports = router;